
package com.exposit.books.web;

import java.util.List;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.exposit.books.domain.Order;
import com.exposit.books.service.PreOrderService;

@Controller
@RequestMapping("/indexx")
public class PreOrderController {

	//@Autowired
	private PreOrderService preorderbooksservice;
	
	@RequestMapping(value = "/indexx", method = RequestMethod.GET)
	public String getAllPreOrders(Model model) {

		List<Order> listOrder = preorderbooksservice.getAllPreOrders();
        model.addAttribute("name", listOrder);

		return "indexx";
	}

	@RequestMapping(value = "/index", method = RequestMethod.POST)
	public String updatePreOrders(@ModelAttribute Order order, 
			Model model) {

		if (order != null) {
			preorderbooksservice.updateOrder(order);			
			model.addAttribute("genre", preorderbooksservice.getAllPreOrders());
		}
		
		model.asMap().remove("genre");
		return "indexx";
	}

}
